package code20210906;

public class C1894 {

	public static void main(String[] args) {
		
		int[] chalk = {51,11,15};
		int k = 60;
		System.out.println(chalkReplacer(chalk,k));
	}
	public static int chalkReplacer(int[] chalk, int k) {
		if(chalk.length==1) return 0;
		int i = 0;
		int sum = 0;
		for(int j=0;j<chalk.length;j++) {
			int c = chalk[j];
			sum += c;
			if(sum>k) return j; 
		}
		k %= sum;
		while(k>=chalk[i]) {
			k -= chalk[i];
			i = (i+1)%chalk.length;
		}
		return i;
    }
}
